package com.gwc.yy.liuxue.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gwc.yy.liuxue.entity.Student;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.sys.dao.UserDao;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
/**
 * 用户扩展Service
 * @author 黎俊涛
 * @version 2017-07-05
 */
@Service
@Transactional(readOnly = true)
public class UserExtendService extends CrudService<UserDao, User> {
	@Autowired
	private StudentService studentService;
	public static final String ADVISER_TPE="4";
	public static final String STUDENT_TYPE="5";
	
	
	public Page<Student> findMyStudentList(Page<Student> page,User user,String adviser) {
		
		user.getSqlMap().put("dsf", " and a.user_type='"+STUDENT_TYPE+"' and adst.adviser='"+adviser+"'");
		
		// 设置分页参数
		user.setPage(new Page<User>(page.getPageNo(), page.getPageSize()));
		// 执行分页查询
		return getStudentList(page,dao.findList(user));
	}
	
	public Page<Student> findAllStudentList(Page<Student> page,User user) {
		user.getSqlMap().put("dsf", " and a.user_type='"+STUDENT_TYPE+"' ");
		// 设置分页参数
		user.setPage(new Page<User>(page.getPageNo(), page.getPageSize()));
		// 执行分页查询
		
		return getStudentList(page,dao.findList(user));
	}
	private Page<Student> getStudentList(Page<Student> page,List<User> list){
		List<Student> result=new ArrayList<Student>();
		for(int i=0;i<list.size();i++){
			Student stu=new Student(list.get(i));
			stu.setAdviser(UserUtils.get(studentService.getAdvisor(stu.getId())));
			result.add(stu);
		}
		page.setList(result);
		return page;
	}
}
